<template>
  <van-nav-bar title="分销佣金" left-text="" left-arrow @click-left="goBack" />
  <van-card v-for="item in member"
    :price="item.amount"
    :desc="'产品名称：'+item.productname"
    :title="'订单号：'+item.productorder.code"
    :thumb="item.thumbs_text"
  >
    <template #tags>
      <van-tag plain type="primary">被推荐人</van-tag>
      {{item.member}}
    </template>
    <template #footer>
      <van-button v-if="item.status == 1" type="primary">已提现</van-button>
      <van-button v-else type="success" @click="getmoney(item.id)">提现</van-button>
    </template>
  </van-card>

</template>

<script setup>
import { onBeforeMount } from "vue";
const { proxy } = getCurrentInstance();
const LoginUser = reactive(
  proxy.$cookies.get("LoginUser") ? proxy.$cookies.get("LoginUser") : {}
);
const goBack = () => {
  proxy.$router.push("/business/index");
};
const member = ref([]);

onBeforeMount(() => {
  getcommissiondata();
});
const getcommissiondata = async () => {
  let result = await Api.commission({
    busid: LoginUser.id,
  });
  if (result.code == 1) {
    member.value = result.data;
  }
};

const getmoney = async(commissionid) =>{
  let resulta = await Api.getcommissionmoney({
    commissionid:commissionid
  })
  if (resulta.code == 1) {
    success('提现成功');
  }else{
    error('提现失败');
  }
  getcommissiondata();
}
</script>
